export class ScoreManager {

    private static _instance: ScoreManager = null;
    private _score: number = 0;
    /** 游戏时长 */
    private _gameTime: number = 0;
    /** 游戏步数 */
    private _gameStep: number = 0;
    
    static getInstance() {
        if (this._instance === null) {
            this._instance = new ScoreManager();
        }
        return this._instance;
    }

    getBestScore() {
        return Number.parseInt(localStorage.getItem("game2048.bestScore")) || 0;
    }

    public addScore(score: number) {
        this._score += score;
        if (this._score > this.getBestScore()) {
            localStorage.setItem("game2048.bestScore", this._score.toString());
        }
    }
    public getScore() {
        return this._score;
    }

    public resetScore() {
        this._score = 0;
        this._gameTime = 0;
        this._gameStep = 0;
    }

    public addGameTime(time: number) {
        this._gameTime += time;
    }

    public getGameTime() {
        return this._gameTime;
    }

    public addGameStep() {
        this._gameStep++; 
    }
    public getGameStep() {
        return this._gameStep; 
    }

}